//
//  NBDiscountVC.m
//  聚超值
//
//  Created by 周abel on 16/4/1.
//  Copyright © 2016年 Zhli. All rights reserved.
//

#import "NBDiscountVC.h"

@interface NBDiscountVC ()

@end

@implementation NBDiscountVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
        
}

#pragma mark -请求数据
- (void)sendRequest {
    
    // 创建请求路径
    NSString *path = [NSString stringWithFormat: @"http://mrobot.pconline.com.cn/s-300/best/cms/getTopicList.xsp?sectionId=0&pageNo=%zd&pageSize=20&v=2.3.0&platform=android", ++self.page];
    
    // 发送请求
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
    // 以JSON格式发送请求
    manger.requestSerializer = [AFJSONRequestSerializer serializer];
    
    // 接受数据解析的模式, 默认为JSON
    manger.responseSerializer = [AFJSONResponseSerializer serializer];
    
    
    [manger POST:path parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        // 获取NBItem
        NSArray *NBItemarr = responseObject[@"data"];

      
        if (NBItemarr.count) {
            
            for (NSDictionary *dict in NBItemarr) {
                
                NBItem *item = [NBItem mj_objectWithKeyValues:dict];
                
                [self.itemArr addObject:item];
            }
            // 刷新UI
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self endRefresh];
                [self.tableView reloadData];
            });
        } else {
            
//            [self.itemArr addObject:item];
            
        }
        // 刷新UI
        dispatch_async(dispatch_get_main_queue(), ^{
            
        });
    
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@", error);
    }];
    
}

@end
